<?php
$this->breadcrumbs = array(
	'Questions'=>array('index'),
	$model->title,
);

$this->menu = array(
	array('label'=>'List Question', 'url'=>array('index')),
	array('label'=>'List Archive', 'url'=>array('archive')),
	array('label'=>'Submit Question', 'url'=>array('create')),
	array('label'=>'Update Question', 'url'=>array('update', 'id'=>$model->id)),
	array('label'=>'Archive Question', 'url'=>'#', 'linkOptions'=>array('submit'=>array('preserve', 'id'=>$model->id), 'confirm'=>'Are you sure you want to archive this item?')),
	array('label'=>'Delete Question', 'url'=>'#', 'linkOptions'=>array('submit'=>array('delete', 'id'=>$model->id), 'confirm'=>'Are you sure you want to delete this item?')),
	array('label'=>'Manage Question', 'url'=>array('admin')),
);
?>

<h1><?php echo $model->title; ?></h1>

<div class="view">

	<table class="collapse">
		<tr>
			<td class="top">

				<div class="span-4">
					<?php
					$default = Yii::app()->request->hostInfo;
					$default .= Yii::app()->getModule('qa')->assetsUrl;
					$default .= '/images/gravatar-150.png';
					$firstname = $model->creator->profile->firstname;
					$config = array(
						'email'=>$model->creator->email,
						'hashed'=>false,
						'default'=>$default,
						'size'=>150,
						'rating'=>'PG',
						'htmlOptions'=>array(
							'alt'=>'Avatar Icon',
							'title'=>CHtml::encode($firstname),
							'class'=>'round stroke',
						),
					);
					$this->widget('qa.widgets.GravatarWidget', $config);
					?>
					<div class="center">
						<b>
							<?php
							echo CHtml::encode($firstname);
							?>
						</b>
					</div>
				</div>
				<div class="clear"></div>
			</td>
			<td class="full top">
				<div class="small right bottom prepend-1 negative">
					<?php
					echo Yii::app()->dateformatter->formatDateTime(
						$model->unixCreatedAt, 'full', 'short'
					);
					?>
				</div>

				<div>
					<?php
					$properties = array('purifyOutput'=>true);
					$this->beginWidget('CMarkdown', $properties);
					echo $model->value;
					$this->endWidget();
					?>
				</div>

				<div class="clear"></div>

				<?php $user = Yii::app()->user; ?>
				<?php if (!$user->isGuest): ?>
					<div class="right">
						<?php
						if ($user->id == 1 || $user->id == $model->createdBy) {
							$url = array('update', 'id'=>$model->id);
							$htmlOptions = array(
								'class'=>'button negative round'
							);
							echo CHtml::link('Update', $url, $htmlOptions);
						}
						
						$htmlOptions = array(
							'rel'=>0,
							'class'=>'reply button round positive last',
						);
						$link = CHtml::link('Reply', '#', $htmlOptions);
						echo $link;
						?>
					</div>
				<?php endif; ?>

				<div class="clear"></div>
			</td>
		</tr>
	</table>

</div>

<?php
foreach ($model->answers as $answer) {
	$this->renderAnswer($answer, 0);
}

if (!Yii::app()->user->isGuest) {
	echo $link;

	$properties = array(
		'id'=>'answer',
		'options'=>array(
			'title'=>'Reply',
			'width'=>'800',
			'autoOpen'=>false,
			'resizable'=>false,
			'modal'=>true,
			'hide'=>'blind',
			'show'=>'blind',
		),
	);
	$this->beginWidget('zii.widgets.jui.CJuiDialog', $properties);
	$view = 'application.modules.qa.views.answer._form';
	echo $this->renderPartial($view, array('model'=>$answerModel));
	$this->endWidget('zii.widgets.jui.CJuiDialog');

	$cs = Yii::app()->clientScript;
	$cs->registerCoreScript('jquery');
	$cs->registerCoreScript('jquery.ui');
	$assetsUrl = Yii::app()->getModule('qa')->assetsUrl;
	$url = "$assetsUrl/js/answer.js";
	$cs->registerScriptFile($url);

	$data = array(
		':id'=>'content',
	);
	$cs->registerScriptContent(
		'history', 'application.modules.qa.views.question.view',
		CClientScript::POS_READY, $data
	);
}
?>